<?php
class promotions extends MY_Model{
    public function __construct() {
        parent::__construct();
    }
    //insert promotion
    public function add_promotion($fields=array()){   
        if(empty($fields)){
            return false;
        }
        $this->db->insert('promotions',$fields);
        return $this->db->insert_id();
    }
    
    //get promotion
    public function get_promotion($conditions=array()){
        if(empty($conditions))
            $query = $this->db->get('promotions');
        else
            $query = $this->db->get_where('promotions',$conditions);
       
        if(isset($conditions['promotion_id']))
            return $query->row();
        return $query->result();
    }
    
    //update promotions
    public function update_promotion($field=array(),$condition=array())
    {
        if(empty($field) || empty($condition)){
            
            return false;
        }
        $this->db->update('promotions',$field,$condition);
        return $this->db->affected_rows();
    }
    
    //delete promotion
    public function delete_promotion($promo_id=false){
        if($promo_id){
            $this->db->where('promotion_id',$promo_id);
            $this->db->delete('promotions');
            return true;
        }
        return false;    
    }
    
    
    public function hash_code($code=false){
        
    }
}
?>